<!--钢筋保护层检测---钢筋保护层检测-1---编辑-->
<template>
  <div class="department">
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left">
          <el-radio-group v-model="radio" size="small" @change="modelType($event)">
            <el-radio-button label="待办"></el-radio-button>
            <el-radio-button label="已办"></el-radio-button>
            <!-- #2b5a9d -->
          </el-radio-group>
        </div>
        <!-- 顶部按钮 -->
        <div class="print">
          <div class="printTable">
            <el-button type="primary" icon="el-icon-search" size="small" v-if="btnWatch && yj_view == true"
              @click="edit(2)">查看</el-button>
            <el-button type="primary" icon="el-icon-circle-plus-outline" size="small" v-if="btnSeeNew && yj_add == true"
              @click="edit(0)">
              新增</el-button>
            <el-button type="primary" icon="el-icon-edit" size="small" v-if="btnSee && yj_edit == true" @click="edit(1)">
              编辑</el-button>
            <el-button type="primary" icon="el-icon-circle-check" size="small" v-if="btnSee && yj_submit == true"
              @click="SubmitText(fId)">提交
            </el-button>
            <el-button type="primary" icon="el-icon-delete" size="small" v-if="btnSee && yj_delete == true"
              @click="rowDelete(fId)">删除
            </el-button>
          </div>
        </div>
      </div>
      <!-- 表格 -->
      <div class="text_table">
        <el-table ref="multipleTableA" :data="tableData" style="width: 100%"
          :height="navigatepageNums > 1 ? 'calc(100% - 20px)' : '100%'" border default-expand-all
          :tree-props="{ children: 'children', hasChildren: 'hasChildren' }" row-key="projectNo" v-loading="loading"
          element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)" @row-click="getRowInfo" highlight-current-row
          @current-change="rowChange" stripe>
          <el-table-column fixed type="index" label="序号" width="50" align="center"></el-table-column>
          <el-table-column prop="projectNo" label="工程编号" width="260"></el-table-column>
          <el-table-column prop="projectFullName" label="工程名称" width="306"></el-table-column>
          <el-table-column prop="projectNature" label="工程类别" width="150">
          </el-table-column>
          <el-table-column prop="protectionNote" label="厚度设计值" width="85" align="center">
          </el-table-column>
          <el-table-column prop="shouldCheckCount" label="厚度应检测" width="85" align="center">
          </el-table-column>
          <el-table-column prop="checkedCount" label="厚度已检测" width="85" align="center">
          </el-table-column>
          <el-table-column prop="price" label="厚度完成率" width="90" align="center">
          </el-table-column>
          <el-table-column prop="checkType" label="检测类型" width="120">
          </el-table-column>
          <el-table-column prop="checkCompanyName" label="检测单位" width="150">
          </el-table-column>
          <el-table-column prop="checkDates" label="厚度检测时间" width="95" align="center">
          </el-table-column>
          <el-table-column prop="checkResult" label="厚度检测结果" width="95" align="center">
          </el-table-column>
          <el-table-column prop="recorderName" label="记录人" width="60" align="center">
          </el-table-column>

          <el-table-column prop="status" label="信息状态" width="70" align="center">
          </el-table-column>
        <!-- <el-table-column
            prop="isHave"
            label="回弹资料"
            width="90"
            align="center"
          >
            <template slot-scope="scope">
              <el-button
                @click="openDialog1(scope.row)"
                @cell-dblclick="openDialog1"
                type="text"
                size="small"
                v-if="scope.row.isHave > 0"
              >
                查看
              </el-button>
            </template>
                                  </el-table-column> -->
          <template slot="empty">
            <img style="width: 285px; height: 208px" src="@/assets/img/undata.png" alt="" />
            <div class="pageFlagText">暂时没有数据哦！</div>
          </template>
        </el-table>
      </div>
      <!--弹框 新增/编辑 -->
      <div class="Control-1 mechanism_dialog">
        <el-dialog :title="dialogText"  :visible.sync="dialogTableVisible" v-loading="loadingDialog"
          element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)">
          <div class="dialogBody common" :style="{ height: dialogHeight }">
            <el-form :model="formData" :rules="rules" ref="formData">
              <div class="tableRow">
                <el-form-item label="检测类型" prop="fChecktype" :label-width="formLabelWidth">
                  <el-select :disabled="dis" v-model="formData.fChecktype" placeholder="请选择检测类型"
                    @change="optionChange($event)">
                    <el-option v-for="(v, i) in Checktype" :key="i" :label="v.fItemValue" :value="v.fItemValue"
                      :disabled="v.disabled">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="检测单位" prop="fCheckcompanyname" :label-width="formLabelWidth">
                  <el-input v-model="formData.fCheckcompanyname" autocomplete="off" disabled></el-input>
                </el-form-item>
              </div>

              <div class="tableRow">
                <el-form-item label="保护层厚度检测时间" prop="fCheckdates" :label-width="formLabelWidth">
                  <el-date-picker v-model="formData.fCheckdates" type="date" :disabled="dis" value-format="yyyy-MM-dd"
                    placeholder="选择日期" autocomplete="off">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="厚度检测结果" prop="fCheckresult" :label-width="formLabelWidth">
                  <el-select :disabled="dis" v-model="formData.fCheckresult" placeholder="请选择厚度检测结果">
                    <el-option v-for="(v, i) in detectionResult" :key="i" :label="v.text" :value="v.text">
                    </el-option>
                  </el-select>
                </el-form-item>
              </div>

              <div class="tableRow">
                <el-form-item label="检测情况概述" prop="fChecksituationdescription" :label-width="formLabelWidth">
                  <el-input v-model="formData.fChecksituationdescription" autocomplete="off" placeholder="请输入"
                    :disabled="dis"></el-input>
                </el-form-item>
                <el-form-item label="记录人" prop="fRecordername" :label-width="formLabelWidth">
                  <el-input v-model="formData.fRecordername" autocomplete="off" disabled></el-input>
                </el-form-item>
              </div>
              <!-- 厚度检测记录表 -->
              <div class="tableRow SelectTime">
                <el-form-item label="厚度检测记录表" prop="fThicknessrecordfile" :label-width="formLabelWidth" class="enclosure"
                  style="height: 100%">
                  <el-input v-show="false" v-model="formData.fThicknessrecordfile" autocomplete="off">
                  </el-input>
                  <div ref="fPhotofilelist" style="
                        height: 25px;
                        line-height: 25px;
                        width: 100%;
                        display: flex;
                        border: 1px solid #d1d7e2;
                        border-radius: 5px;
                        margin: 8px 0 2px 0;
                      ">
                    <div v-for="(v, i) in fPhotofilelist" :key="i" style="margin: 2px 3px; height: 87%"
                      @click="openPdfs(v)">
                      <img style="max-width: 100%; max-height: 100%" src="@/assets/img/pdf.png" />
                    </div>
                  </div>

                  <el-button v-show="!dis" type="primary" icon="el-icon-search" size="small" @click="operation('1')"
                    style="margin: 8px 0 2px 3px">操作</el-button>
                </el-form-item>
                <!-- 厚度检测报告 -->
                <el-form-item label="厚度检测报告" prop="fThicknessreportfile" :label-width="formLabelWidth" class="enclosure"
                  style="height: 100%">
                  <el-input v-if="false" v-model="formData.fThicknessreportfile" autocomplete="off">
                  </el-input>
                  <div ref="fSourcefilelist" style="
                        height: 25px;
                        line-height: 25px;
                        width: 100%;

                        display: flex;
                        border: 1px solid #d1d7e2;
                        border-radius: 5px;
                        margin: 8px 0 2px 0;
                      ">
                    <div v-for="(v, i) in fSourcefilelist" :key="i" style="margin: 2px 3px; height: 87%"
                      @click="openPdfs(v)">
                      <img style="max-width: 100%; max-height: 100%" src="@/assets/img/pdf.png" />
                    </div>
                  </div>
                  <el-button v-show="!dis" type="primary" icon="el-icon-search" size="small" @click="operation('2')"
                    style="margin: 8px 0 2px 3px">操作</el-button>
                </el-form-item>
              </div>

              <el-form-item class="newlyAdded_btn">
                <el-button type="primary" @click="submitForm('formData')">保存</el-button>
              </el-form-item>
            </el-form>
          </div>
        </el-dialog>
      </div>
      <!-- 上传附件  -->
      <div class="Control-1 mechanism_dialog enclosure">
        <el-dialog title="上传附件"  top="-17vh" :visible.sync="dialogTableVisibleTexts"
          v-loading="loadingDialogTexts" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)">
          <div class="dialogBody common" :style="{ height: '240px' }">
            <el-upload action="action" ref="upload" list-type="picture-card" :file-list="fPhotofilelist"
              :auto-upload="false" :on-change="handleChange" accept=".pdf">
              <i slot="default" class="el-icon-plus"></i>
              <div style="width: 100%; height: 100%; text-align: center" slot="file" slot-scope="{ file }">
                <div style="
                      width: 100%;
                      height: 100%;
                      display: flex;
                      justify-content: center;
                      align-items: center;
                    " class="images">
                  <img style="max-width: 100%; max-height: 100%" src="@/assets/img/pdf.png" />
                </div>
                <span class="el-upload-list__item-actions">
                  <span title="文件预览" class="el-upload-list__item-preview" @click="openPdf(file)">
                    <i class="el-icon-zoom-in"></i>
                  </span>
                  <span title="删除文件" class="el-upload-list__item-delete" @click="handleRemove(file)">
                    <i class="el-icon-delete"></i>
                  </span>
                </span>
              </div>
            </el-upload>
            <div>
              <div style="position: absolute; right: 5px; bottom: 0">
                <el-button type="primary" @click="submitUpload(enclosureImg)">保存</el-button>
              </div>
            </div>
          </div>
        </el-dialog>
      </div>
      <div class="Control-1 mechanism_dialog enclosure">
        <el-dialog title="上传附件"  top="-17vh" :visible.sync="dialogTableVisibleTexts1"
          v-loading="loadingDialogTexts1" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)">
          <div class="dialogBody common" :style="{ height: '240px' }">
            <el-upload action="action" ref="upload1" list-type="picture-card" :file-list="fSourcefilelist"
              :auto-upload="false" :on-change="handleChange1" accept=".pdf">
              <i slot="default" class="el-icon-plus"></i>
              <div style="width: 100%; height: 100%; text-align: center" slot="file" slot-scope="{ file }">
                <div style="
                      width: 100%;
                      height: 100%;
                      display: flex;
                      justify-content: center;
                      align-items: center;
                    " class="images">
                  <img style="max-width: 100%; max-height: 100%" src="@/assets/img/pdf.png" />
                </div>
                <span class="el-upload-list__item-actions">
                  <span title="文件预览" class="el-upload-list__item-preview" @click="openPdf(file)">
                    <i class="el-icon-zoom-in"></i>
                  </span>
                  <span title="删除文件" class="el-upload-list__item-delete" @click="handleRemove(file)">
                    <i class="el-icon-delete"></i>
                  </span>
                </span>
              </div>
            </el-upload>
            <div>
              <div style="position: absolute; right: 5px; bottom: 0">
                <el-button type="primary" @click="submitUpload1(enclosureImg)">保存</el-button>
              </div>
            </div>
          </div>
        </el-dialog>
      </div>
      <div class="Control-2">
        <el-dialog :title="fFileName"  :visible.sync="dialogPdf">
          <div :style="{ height: dialogHeighta }">
            <iframe :src="pdfUrl" width="100%" height="100%" frameborder="0"></iframe>
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getProtectionthicknessEditList,
  getProtectionByFormId,
  addProtectionthickness,
  deleteProtectionthickness,
  submitProtectionthickness,
  getCheckTypeByUserId,
  upload,
} from "@/api/request.js";
export default {
  inject: ["reload"],
  name: "Home",
  data() {
    return {
      name: "Steel-2Text",
      yj_view: null,
      yj_add: null,
      yj_edit: null,
      yj_delete: null,
      yj_submit: null,
      navigatepageNums: null,
      // 上传附件
      fPhotofilelist: [],
      fSourcefilelist: [],
      loadingDialogTexts: false,
      loadingDialogTexts1: false,
      dialogTableVisibleTexts: false,
      dialogTableVisibleTexts1: false,
      attachmentDetails: [],
      attachmentDetails1: [],
      timestamp1: null,
      timestamp2: null,
      dis: false,
      dialogPdf: false,
      pdfUrl: "",
      fFileName: "",
      dialogHeighta: "",
      enclosureImg: null,
      // 上传附件

      Checktype: [], //检测类型
      btnWatch: false, //查看按钮显示隐藏
      btnSee: true, //编辑，提交，删除按钮显示隐藏
      btnSeeNew: true, //新增按钮显示隐藏
      radio: "待办",
      dialogHeight: "",

      dialogHeights: "240px",
      formLabelWidth: "120px",
      fId: "", //当前数据fId
      loading: false,
      userInfo: {}, //登录用户
      // 列表
      getList: {
        companyId: "", // 当前登陆用户机构id
        userId: "", // 当前登陆用户id
        modelType: "0", // 0-待办  1-已办
      },
      rules: {
        fChecktype: [{ required: true, trigger: "blur" }],
        fCheckcompanyname: [{ required: true, trigger: "blur" }],
        fCheckdates: [{ required: true, trigger: "blur" }],
        fCheckresult: [{ required: true, trigger: "blur" }],
        fRecordername: [{ required: true, trigger: "blur" }],
        fThicknessrecordfile: [{ required: true, trigger: "blur" }],
        fThicknessreportfile: [{ required: true, trigger: "blur" }],
        fPhotofilelist: [{ required: true, message: "请选择厚度记录表" }],
        fSourcefilelist: [{ required: true, message: "请选择厚度检测报告" }],
      },
      // 新增/编辑
      detectionResult: [{ text: "合格" }, { text: "不合格" }],
      dialogText: "",
      dialogTableVisible: false,
      loadingDialog: false,
      fCheckdates: "", //试验检测日期
      row: { protectionNote: "", status: "" },
      formData: {
        fId: "",
        fProjectid: "666", //工程id
        fProjectname: "测试工程", //工程简称
        fProjectfullname: "测试工程全称", //工程全称
        fChecktype: "测试类型", //检测类型
        fCheckcompanyid: "6666", //检测单位id
        fCheckcompanyname: "测试检测单位", //检测单位简称
        fCheckcompanyfullname: "测试检测单位全称", //检测单位全称
        fCheckdates: "", // 保护层厚度检测时间
        fCheckresult: "", // 检测结果
        fChecksituationdescription: "", // 检测情况概述
        fRecorderid: "", // 记录人id
        fRecordername: "", // 记录人name
        fThicknessrecordfile: "", // 记录表id
        fThicknessreportfile: "", // 报告表id
        //用户信息
        userId: "333", //当前登陆用户id
        userName: "测试人员", //当前登陆用户名称
        companyId: "222", //当前登陆用户机构id
        companyName: "测试机构", //当前登陆用户机构名称
        //删除文件id集合--修改时传
        recordfiles: [
          {
            fId: "xxx", //文件id
          },
        ],
      },
      tableData: [], //表格数据列表
    };
  },
  created() {
    this.userInfo = JSON.parse(sessionStorage.getItem("GxEmbedded_userInfo"));
    this.getList.userId = this.userInfo.userId;
    this.getList.companyId = this.userInfo.companyId;
  },
  mounted() {
    this.getHeight();
    this.getDataList(this.getList);
    this.testType();
    this.btnRole(this.name);
  },

  methods: {
    btnRole(name) {
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("GxEmbedded_ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          console.log(item);
          btnStr.push(item.fEncode);
        });
        this.yj_view = btnStr.includes("yj_view");
        this.yj_add = btnStr.includes("yj_add");
        this.yj_edit = btnStr.includes("yj_edit");
        this.yj_delete = btnStr.includes("yj_delete");
        this.yj_submit = btnStr.includes("yj_submit");
      } else {
        this.yj_view = true;
        this.yj_add = true;
        this.yj_edit = true;
        this.yj_delete = true;
        this.yj_submit = true;
      }
    },
    // 上传附件
    // 上传文件
    handleChange(res) {
      this.attachmentDetails.push(res);
      this.enclosureImg = new FormData(); //new一个formData事件
      this.enclosureImg.append("folderid", this.timestamp1); //将file属性添加到formData里

      this.enclosureImg.append("file", res.raw); //将file属性添加到formData里

      this.enclosureImg.append("userId", this.userInfo.userId); //将file属性添加到formData里
      this.enclosureImg.append("userName", this.userInfo.realName); //将file属性添加到formData里

      upload(this.enclosureImg).then((i) => {
        i[0]["name"] = res.name;
        i[0]["url"] = res.url;
        this.fPhotofilelist.push(i[0]);
      });
    },
    handleChange1(res) {
      this.attachmentDetails1.push(res);
      this.enclosureImg = new FormData(); //new一个formData事件
      this.enclosureImg.append("folderid", this.timestamp2); //将file属性添加到formData里
      this.enclosureImg.append("file", res.raw); //将file属性添加到formData里
      this.enclosureImg.append("userId", this.userInfo.userId); //将file属性添加到formData里
      this.enclosureImg.append("userName", this.userInfo.realName); //将file属性添加到formData里

      upload(this.enclosureImg).then((i) => {
        i[0]["name"] = res.name;
        i[0]["url"] = res.url;
        this.fSourcefilelist.push(i[0]);
      });
    },
    // 操作按钮
    operation(num) {
      this.operationNum = num;
      if (num == 1) {
        this.dialogTableVisibleTexts = true;
        this.$refs.fPhotofilelist.style.border = "1px solid #DCDFE6";
      } else if (num == 2) {
        this.$refs.fSourcefilelist.style.border = "1px solid #DCDFE6";
        this.dialogTableVisibleTexts1 = true;
      }
    },
    // 预览
    openPdf(file) {
      this.dialogPdf = true;
      this.pdfUrl = file.url;
      this.fFileName = file.name;
    },
    // 保留文件，点击查看
    openPdfs(v) {
      this.dialogPdf = true;
      this.pdfUrl = v.url;
      this.fFileName = v.name;
    },
    // 移除
    handleRemove(file) {
      if (this.operationNum == 1) {
        this.$refs.upload.handleRemove(file);
        for (let index = 0; index < this.fPhotofilelist.length; index++) {
          if (file.uid == this.fPhotofilelist[index].uid) {
            if (this.fPhotofilelist[index].atta == undefined) {
              this.formData.recordfiles.push({
                fId: this.fPhotofilelist[index].fId,
              });
            } else {
              this.formData.recordfiles.push({
                fId: this.fPhotofilelist[index].atta.fId,
              });
            }
            this.fPhotofilelist.splice(index, 1);
          }
        }
      } else if (this.operationNum == 2) {
        this.$refs.upload1.handleRemove(file);
        for (let index = 0; index < this.fSourcefilelist.length; index++) {
          if (file.uid == this.fSourcefilelist[index].uid) {
            if (this.fSourcefilelist[index].atta == undefined) {
              this.formData.recordfiles.push({
                fId: this.fSourcefilelist[index].fId,
              });
            } else {
              this.formData.recordfiles.push({
                fId: this.fSourcefilelist[index].atta.fId,
              });
            }
            this.fSourcefilelist.splice(index, 1);
          }
        }
      }
    },
    // 保存
    submitUpload() {
      this.dialogTableVisibleTexts = false;
    },
    submitUpload1() {
      this.dialogTableVisibleTexts1 = false;
    },

    // 上传附件

    // 待办/已办
    modelType(e) {
      if (e == "待办") {
        this.getList.modelType = "0";
        this.btnSeeNew = true;
        this.btnSee = true;
        this.btnWatch = false;
      } else {
        this.btnSeeNew = false;
        this.btnSee = false;
        this.btnWatch = true;
        this.getList.modelType = "1";
      }
      this.getDataList(this.getList);
    },
    // 获取列表数据
    getDataList(id) {
      this.loading = true;
      this.fId = "";
      getProtectionthicknessEditList(id)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            setTimeout(() => {
              that.loading = false;
              that.tableData = this.tranListToTreeData(res.data);
              that.navigatepageNums = that.tableData.length;
              that.$nextTick(() => {
                that.$refs.multipleTableA.doLayout();
              });
            }, 200);
          } else {
            this.$message.error("获取列表数据失败", res.msg);
            this.loading = false;
            return false;
          }
        })
        .catch(() => {
          console.log("获取列表数据失败");
          this.loading = false;
          return false;
        });
    },
    // 对列表页进行上下级排列
    tranListToTreeData(data) {
      let result = [];
      if (!Array.isArray(data)) {
        return result;
      }
      // 清除已存在的children 重新赋值
      data.forEach((item) => {
        delete item.children;
      });

      let map = {};
      data.forEach((item) => {
        map[item.projectNo] = item;
      });

      data.forEach((item) => {
        let parent = map[item.parentId];
        if (parent) {
          (parent.children || (parent.children = [])).push(item);
        } else {
          result.push(item);
        }
      });
      return result;
    },
    // 获取当前日期
    getDate() {
      var time = new Date();
      const y = time.getFullYear();

      var m = time.getMonth() + 1 + "";
      m = (m < 10 ? "0" : "") + m;

      var d = time.getDate() + "";
      d = (d < 10 ? "0" : "") + d;

      this.formData.fCheckdates = `${y}-${m}-${d}`;
    },
    // 新增/编辑/查看
    edit(num) {
      this.fPhotofilelist = [];
      this.fSourcefilelist = [];
      this.imgListJl = [];
      this.imgListBg = [];
      this.formData = {
        fId: "",
        fProjectid: "", //工程id
        fProjectname: "", //工程简称
        fProjectfullname: "", //工程全称
        fChecktype: "", //检测类型
        fCheckcompanyid: "", //检测单位id
        fCheckcompanyname: "", //检测单位简称
        fCheckcompanyfullname: "", //检测单位全称
        fCheckdates: "", // 保护层厚度检测时间
        fCheckresult: "", // 检测结果
        fChecksituationdescription: "", // 检测情况概述
        fRecorderid: "", // 记录人id
        fRecordername: "", // 记录人name
        fThicknessrecordfile: "", // 记录表id
        fThicknessreportfile: "", // 报告表id
        //用户信息
        userId: "", //当前登陆用户id
        userName: "", //当前登陆用户名称
        companyId: "", //当前登陆用户机构id
        companyName: "", //当前登陆用户机构名称
        //删除文件id集合--修改时传
        recordfiles: [],
      };
      if (num == 0) {
        if (this.row.protectionNote != "" && this.row.status == "") {
          this.dis = false;
          this.dialogTableVisible = true;
          // 新增
          this.dialogText = "新增厚度检测信息";
          this.getDate();
          this.formData.fRecordername = this.userInfo.realName;
          this.formData.fProjectid = this.row.projectId;
          this.formData.fProjectname = this.row.projectFullName;
          this.formData.fProjectfullname = this.row.projectFullName;
          this.formData.fRecorderid = this.userInfo.userId;
          //用户信息
          this.formData.userId = this.userInfo.userId;
          this.formData.userName = this.userInfo.realName;
          this.formData.companyId = this.userInfo.companyId;
          this.formData.companyName = this.userInfo.companyName;
          this.timestamp1 = "EQUIP" + Date.parse(new Date()) + "JL";
          this.timestamp2 = "EQUIP" + Date.parse(new Date()) + "BG";
          this.formData.fThicknessrecordfile = this.timestamp1; // 记录表id
          this.formData.fThicknessreportfile = this.timestamp2; // 报告表id
        } else {
          return this.$message.error("请选择有厚度设计值,且无信息状态的数据");
        }
      } else if (num == 1) {
        // 编辑
        if (this.fId != "") {
          this.loadingDialog = true;
          this.dialogTableVisible = true;
          this.dis = false;
          getProtectionByFormId({ fId: this.fId })
            .then((res) => {
              if (res.errcode == 0) {
                var that = this;
                that.dialogText = "编辑厚度检测信息";
                that.loadingDialog = false;
                that.formData = res.data.thickness;
                that.timestamp1 = res.data.thickness.fThicknessrecordfile;
                that.timestamp2 = res.data.thickness.fThicknessreportfile;
                that.fPhotofilelist = res.data.recordfile; //记录表文件
                that.fSourcefilelist = res.data.reportfile; //报告表文件
                that.formData.recordfiles = [];
              } else {
                this.$message.error("编辑失败", res.msg);
                this.loadingDialog = false;
              }
            })
            .catch(() => {
              console.log("编辑失败");
              this.loadingDialog = false;
            });
        } else {
          return this.$message.error("请先选择需要编辑的数据");
        }
      } else {
        //查看
        if (this.fId != "") {
          this.loadingDialog = true;
          this.dialogTableVisible = true;
          this.dis = true;
          getProtectionByFormId({ fId: this.fId })
            .then((res) => {
              if (res.errcode == 0) {
                var that = this;
                that.dialogText = "查看厚度检测信息";
                that.loadingDialog = false;
                that.formData = res.data.thickness;
                that.fPhotofilelist = res.data.recordfile; //记录表文件
                that.fSourcefilelist = res.data.reportfile; //报告表文件
              } else {
                this.$message.error("查看失败", res.msg);
                this.loadingDialog = false;
              }
            })
            .catch(() => {
              console.log("查看失败");
              this.loadingDialog = false;
              return false;
            });
        } else {
          return this.$message.error("请先选择需要查看的数据");
        }
      }
    },
    // 根据检测类型选择检测单位
    optionChange(e) {
      for (let index = 0; index < this.Checktype.length; index++) {
        const element = this.Checktype[index];
        if (element.fItemValue == e) {
          this.formData.fCheckcompanyname = element.fCompanyName;
          this.formData.fCheckcompanyid = element.fCompanyId;
          this.formData.fCheckcompanyfullname = element.fCompanyFullName;
        }
      }
    },
    // 保存
    submitForm() {
      this.$refs.formData.validate((valid) => {
        if (valid) {
          if (this.fPhotofilelist.length == 0) {
            this.$refs.fPhotofilelist.style.border = "1px solid red";
          } else if (this.fSourcefilelist.length == 0) {
            this.$refs.fSourcefilelist.style.border = "1px solid red";
          } else {
            this.loading = true;
            addProtectionthickness(this.formData)
              .then((res) => {
                if (res.errcode == 0) {
                  this.loading = false;
                  this.reload();
                  this.$message.success("保存成功");
                } else {
                  this.$message.error("保存失败", res.msg);
                  this.loading = false;
                }
              })
              .catch(() => {
                this.$message.error("保存失败");
                this.loading = false;
              });
          }
        } else {
          this.$message.error("请填写必填项");
          return false;
        }
      });
    },
    // 提交
    SubmitText(id) {
      if (id != "") {
        this.$confirm("是否继续提交?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.loading = true;
            submitProtectionthickness({
              fId: id,
              userId: this.userInfo.userId,
              userName: this.userInfo.realName,
            })
              .then((res) => {
                if (res.errcode == 0) {
                  this.loading = false;
                  this.reload();
                  this.$message.success("提交成功");
                } else {
                  this.$message.error("提交失败", res.msg);
                  this.loading = false;
                }
              })
              .catch(() => {
                console.log("提交失败");
                this.loading = false;
              });
          })
          .catch(() => {
           this.$message("取消提交");
          });
      } else {
        return this.$message.error("请先选择需要提交的数据");
      }
    },
    // 删除
    rowDelete(id) {
      if (id != "") {
        this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.loading = true;
            deleteProtectionthickness({ fId: id })
              .then((res) => {
                if (res.errcode == 0) {
                  this.loading = false;
                  this.reload();
                  this.$message.success("删除成功");
                } else {
                  this.$message.error("删除失败", res.msg);
                  this.loading = false;
                }
              })
              .catch(() => {
                console.log("删除失败");
                this.loading = false;
              });
          })
          .catch(() => {
           this.$message("取消删除");
          });
      } else {
        return this.$message.error("请先选择需要删除的数据");
      }
    },

    // 点击当前行
    getRowInfo(e) {
      this.row = e;
      this.fId = e.formId;
      if (this.getList.modelType == "0") {
        if (e.protectionNote == "") {
          this.btnSeeNew = false;
          this.btnSee = false;
        } else {
          if (e.status == "未提交") {
            this.btnSeeNew = false;
            this.btnSee = true;
          }
          if (e.status == "" && e.protectionNote != "") {
            this.btnSee = false;
            this.btnSeeNew = true;
          }
        }
      } else {
        if (e.status == "已完成" && e.protectionNote != "") {
          this.btnWatch = true;
        } else {
          this.btnWatch = false;
        }
      }
    },

    // 点击当前行变色
    rowChange(val) {
      this.currentRow = val;
    },
    // 检测类型
    testType() {
      if (this.userInfo.companyId != "") {
        getCheckTypeByUserId({ companyId: this.userInfo.companyId }).then(
          (res) => {
            if (res.errcode == 0) {
              this.Checktype = res.data.Checktype;
            } else {
              this.$message.error("检测类型", res.msg);
            }
          }
        );
      }
    },
    // 获取页面容器高度
    getHeight() {
      var h = document.documentElement.clientHeight; //获取页面可见高度
      this.dialogHeight = h * 0.5 + "px";
      this.dialogHeighta = h * 0.888 + "px";
    },
  },
};
</script>

<style scoped>
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.pageFlagText {
  color: #171a1d;
  font-size: 16px;
}

a {
  text-decoration: none;
  color: #000;
}
</style>